package com.example.apple.ddhr_new.activity.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;

import com.example.apple.ddhr_new.R;

import androidx.annotation.Nullable;

public class BLinearLayout extends View {
    public BLinearLayout(Context context) {
        super(context);
        init();
    }

    public BLinearLayout(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public BLinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }
    private void init() {
        paint = new Paint();
        paint.setAntiAlias(true);
    }

    float percent = (float) 1.0;
    private Paint paint;
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        paint.setColor(getResources().getColor(R.color.white));
        paint.setStyle(Paint.Style.FILL);
        Path path = new Path();
        path.addRect(new RectF(0,0,getWidth(),getHeight()),Path.Direction.CW);
        Path path2 = new Path();
        path2.moveTo(0,0);

        path2.quadTo(getWidth()/2,getHeight()+getHeight()*percent,getWidth(),0);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            path.op(path2, Path.Op.DIFFERENCE);
        }
        canvas.drawPath(path,paint);
    }
    public  void  setPercent(float percent){
            this.percent =percent;
            invalidate();
    }
}
